﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using Zzj.Model;

namespace Zzj
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        public static Config config = null;

        private static object _lock = new object();
        private static System.Threading.Mutex IMutex;

        public static Config getConfig()
        {
            if (config == null)
            {
                lock (_lock)
                {
                    if (config == null)
                    {
                        config = new Config();
                    }
                }
            }
            return config;
        }

        protected override void OnStartup(StartupEventArgs e)
        {
            string MyAppID = "Zzj";//运行进程互斥标识名称 可自行修改
            IMutex = new System.Threading.Mutex(true, MyAppID);
            if (IMutex.WaitOne(0, false))
            {
                base.OnStartup(e);
                App.getConfig().SettingPassword = ConfigurationManager.AppSettings["SettingPassword"];
                App.getConfig().HttpServerIp = ConfigurationManager.AppSettings["HttpServerIp"];
                App.getConfig().HttpServerPort = ConfigurationManager.AppSettings["HttpServerPort"];
                App.getConfig().IDCardDevice = ConfigurationManager.AppSettings["IDCardDevice"];
                App.getConfig().IDCardCode = ConfigurationManager.AppSettings["IDCardCode"];
                App.getConfig().PrintDuration = ConfigurationManager.AppSettings["PrintDuration"];
                App.getConfig().PrinterStatusPrompt = ConfigurationManager.AppSettings["PrinterStatusPrompt"];
                App.getConfig().SSIDCardPort = ConfigurationManager.AppSettings["SSIDCardPort"];
                App.getConfig().SSIDCardPortBaudRate = ConfigurationManager.AppSettings["SSIDCardPortBaudRate"];
                App.getConfig().CardReaderDeviceType = ConfigurationManager.AppSettings["CardReaderDeviceType"];
                App.getConfig().MaxWeigh = ConfigurationManager.AppSettings["MaxWeigh"];
                App.getConfig().IfStatement = ConfigurationManager.AppSettings["IfStatement"];
                App.getConfig().statementMessage = ConfigurationManager.AppSettings["statementMessage"];
                App.getConfig().PhotoQuality = ConfigurationManager.AppSettings["PhotoQuality"];
                App.getConfig().ClearMultiples = ConfigurationManager.AppSettings["ClearMultiples"];
                App.getConfig().PhotoWidth = ConfigurationManager.AppSettings["PhotoWidth"];
                App.getConfig().PhotoHeight = ConfigurationManager.AppSettings["PhotoHeight"];
                App.getConfig().SJIDCardPort = ConfigurationManager.AppSettings["SJIDCardPort"];
                App.getConfig().MacCard = ConfigurationManager.AppSettings["MacCard"];

                //App.getConfig().tipsPrint= ConfigurationManager.AppSettings["tipsPrint"];
            }
            else
            {
                MessageBox.Show("程序已经在运行！", "提示", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                this.Shutdown();
            }
        }
    }
}